import React, {useEffect} from "react";
import {View} from "@tarojs/components";
import {messageType} from "@/pages/message/type";
import http from "@/request";
import user from "@/store/user"
import "./index.scss"

const MessageList: React.FC = () => {
    const [messages, setMessages] = React.useState<messageType[]>([]);

    const getList = () => {
        http.post('/disp/biz/message/page', {
            pageNum: 1,
            pageSize: 9999,
        }).then((res) => {
            setMessages(res.data.list);
            readAll()
        })
    }
    const readAll = () => {
        http.post('/disp/biz/message/readAllMsg', {
            userCode: user.info?.userCode
        })
    }
    useEffect(() => {
        getList()
    }, []);
    return (
        <View className={'page'}>
            {
                messages.map((message) => (<View className="list-item-container">
                    <View className="item-row flex-row flex-item">
                        <View className="item-value flex1">{message.msgContent} </View>
                        <View className={`msg-type ${message.msgType}`}>{message.msgTypeName}</View>
                    </View>
                    <View>创建人：{message.createUserName}</View>
                    <View>创建日期：{message.createTime}</View>
                    <View className="item-value">由 {message.createUserName} 更新</View>
                </View>))
            }
        </View>
    )
}
export default MessageList;